package com.books.config.im;

import com.books.im.handler.MsgHandlerFactory;
import com.books.im.server.ImServerStart;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

@Slf4j
@Configuration
public class ImServerConfig {

    @Value ("${im.server.port}")
    private int imPort;


    @Bean
    ImServerStart imServerStart(){
        try {
            //启动tio服务
            ImServerStart serverStart = new ImServerStart (imPort);
            serverStart.start ();

            //初始化消息处理器类别
            MsgHandlerFactory.init ();

            return serverStart;
        } catch (IOException e) {
            log.error (" tio server 启动失败",e);
        }
        return null;
    }

}
